<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加参数</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
	<div class="layui-form-item">
        <label class="layui-form-label required">参数名称</label>
        <div class="layui-input-block">
            <input type="text" name="parameterName" lay-verify="required" lay-reqtext="参数名称不能为空" placeholder="请输入参数名称" autocomplete="off" class="layui-input">            
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">参数类型</label>
        <div class="layui-input-block">
            <select name="parameterType" lay-filter="parameterType" id="parameterType" lay-verify="required" lay-reqtext="参数类型不能为空">                     
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">排序</label>
        <div class="layui-input-block">
             <input type="number" name="sort" lay-verify="required" lay-reqtext="排序不能为空" placeholder="请输入排序号" autocomplete="off" class="layui-input">            
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
            <button class="layui-btn layui-btn-normal" id="cancel">取消</button>
        </div>
    </div>
</div>
<script src="../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form','layedit'], function () {
        var form = layui.form,
            layer = layui.layer,
            layarea = layui.layarea,
            layedit = layui.layedit,
            $ = layui.$;
        
      //加载下拉列表
        layer.ready(function(){
        	$.ajax({
                type : "POST",
                url : "../parameter/getParameterType",
                contentType: "application/json;charset=utf-8",
                data : JSON.stringify({"parameterType":""}),
                dataType: "json",
                success : function(result) {
	     		    var data=result.data;
	     		    var info = "<option value=''>请选择</option>";
	     		    for (var i = 0; i < data.length; i++) {    
	     		        info += "<option value=" + data[i].parameterType + ">" + data[i].typeName + "</option>";        
	     		    }
	     		    $("#parameterType").append(info);
	     		    form.render('select');
                }    
     		 });
         }); 
       
        //初始化表单，要加上，不然刷新部分组件可能会不加载
        form.render();
        var iframeIndex = parent.layer.getFrameIndex(window.name);       
        
        //监听提交
        form.on('submit(saveBtn)', function (data) {
        	$.ajax({
                type : "POST", //提交方式
                url : "../parameter/save",//路径
                contentType: "application/json;charset=utf-8",
                data : JSON.stringify(data.field),//数据，这里使用的是Json格式进行传输
                dataType: "json",
                success : function(result) {//返回数据根据结果进行相应的处理
                    if (result.code == "0") {
                        var index = layer.msg("成功", {
                            time: 300 //如果不配置，默认是3秒）
                        },function () {
                        	// 关闭弹出层
                            layer.close(index);
                            parent.layer.close(iframeIndex);
                        })
                    }else{
                        layer.msg(result.msg);
                    }
                }
            });
            return false;
        });
        
        $('#cancel').on("click", function () {
             parent.layer.close(iframeIndex);
        });
    });
</script>
</body>
</html>